using System;
using System.Collections;
using System.Collections.Generic;
using Gtk;
using System.Linq;
namespace JiveMessengerLinux
{
    public partial class AddUserEmoticons : Gtk.Window
    {
        public Dictionary<string, string> MyEmoticons;
        private readonly string _customEmoticonFolder;

        public AddUserEmoticons(SerializableDictionary<string, SerializableDictionary<string, string>> userEmoticons, Dictionary<string, string> myEmoticons, string customEmoticonFolder)
            : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            
            this.MyEmoticons = myEmoticons;
            this._customEmoticonFolder = customEmoticonFolder;
            foreach (KeyValuePair<string, SerializableDictionary<string, string>> kvp in userEmoticons)
            {
                //ListBoxItem lbi = new ListBoxItem
                //{
                //    Tag = kvp.Value,
                //    Content = kvp.Key,
                //    FontWeight = FontWeights.Bold,
                //    Height = 30
                //};
                //lbi.FontSize = 14;
                //  this.lstEmoticonUser.Items.Add(lbi);
                Gtk.Button bn = Gtk.Button.NewWithLabel(kvp.Key);

                bn.Data.Add(kvp.Key, kvp.Value);

                bn.Clicked += (s, e) =>
                    {
                        Gtk.Button button = s as Button;
                        if (button != null)
                        {
                            Dictionary<string, string> emoticons = new Dictionary<string, string>();
                            foreach (DictionaryEntry dic in button.Data)
                            {
                                emoticons = (Dictionary<string, string>)dic.Value;
                                break;
                            }
                            UserEmoticons page = new UserEmoticons(emoticons, this.MyEmoticons, this._customEmoticonFolder);
                            page.ShowAll();
                        //this.vboxUserEmoticons = new VBox();
                            if (this.vboxUserEmoticons.Children.Length > 0)
                            {
                                UserEmoticons oldPage = this.vboxUserEmoticons.AllChildren.Cast<UserEmoticons>().First();
                                this.vboxUserEmoticons.Remove(oldPage);
                                
                            }
                            this.vboxUserEmoticons.PackStart(page,true,true,0);
                            this.vboxUserEmoticons.ShowAll();
                            //  frame1.Add(page);
                            //     frame1.ShowAll();
                            // vboxEmoticons = new VBox();
                            //   vboxEmoticons.PackStart(page);
                        }
                    };
                bn.ShowAll();
                this.vboxUsers.PackStart(bn, false, false, 0);
                this.vboxUsers.ShowAll();
               
                Button firstbn = this.vboxUsers.Children[0] as Button;
                if (firstbn != null) firstbn.Click();
            }
            // if (this.lstEmoticonUser.Items.Count > 0)
            //    this.lstEmoticonUser.SelectedItem = this.lstEmoticonUser.Items[0];
        }

        protected void OnBnAddUserEmoticonsClicked(object sender, EventArgs e)
        {
        
        }
    }
}

